package cn.wuxing.mediation.web.controller.schedule;

import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.wuxing.mediation.system.domain.vo.ShiftVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wuxing.mediation.common.annotation.Log;
import cn.wuxing.mediation.common.core.controller.BaseController;
import cn.wuxing.mediation.common.core.domain.AjaxResult;
import cn.wuxing.mediation.common.enums.BusinessType;
import cn.wuxing.mediation.system.domain.ShiftScheduling;
import cn.wuxing.mediation.system.service.IShiftSchedulingService;
import cn.wuxing.mediation.common.utils.poi.ExcelUtil;
import cn.wuxing.mediation.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 庭室情况Controller
 *
 * @author mediation
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/system/scheduling")
public class ShiftSchedulingController extends BaseController {
    @Resource
    private IShiftSchedulingService shiftSchedulingService;

    /**
     * 查询庭室情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShiftScheduling shiftScheduling) {
        startPage();
        List<ShiftScheduling> list = shiftSchedulingService.selectShiftSchedulingList(shiftScheduling);
        return getDataTable(list);
    }

    /**
     * 导出庭室情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:export')")
    @Log(title = "庭室情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShiftScheduling shiftScheduling) {
        List<ShiftScheduling> list = shiftSchedulingService.selectShiftSchedulingList(shiftScheduling);
        list.forEach(i -> {
            if (i.getChambersStatus() != null) {
                if (!i.getChambersStatus().equals("")) {
                    if (i.getChambersStatus().equals("0")) {
                        i.setChambersStatus("待调解");
                    }
                    if (i.getChambersStatus().equals("1")) {
                        i.setChambersStatus("已调解");
                    }
                }
            }
        });
        ExcelUtil<ShiftScheduling> util = new ExcelUtil<ShiftScheduling>(ShiftScheduling.class);
        util.exportExcel(response, list, "庭室情况数据");
    }

    /**
     * 导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<ShiftVo> util = new ExcelUtil<ShiftVo>(ShiftVo.class);
        util.importTemplateExcel(response, "庭室情况");
    }

    @Log(title = "庭室情况", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:scheduling:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<ShiftScheduling> util = new ExcelUtil<ShiftScheduling>(ShiftScheduling.class);
        List<ShiftScheduling> shiftSchedulingList = util.importExcel(file.getInputStream());
        String message = shiftSchedulingService.importShiftScheduling(shiftSchedulingList, updateSupport);
        return success(message);
    }

    /**
     * 获取庭室情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(shiftSchedulingService.selectShiftSchedulingById(id));
    }

    /**
     * 新增庭室情况
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:add')")
    @Log(title = "庭室情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShiftScheduling shiftScheduling) {
        return toAjax(shiftSchedulingService.insertShiftScheduling(shiftScheduling));
    }

    /**
     * 修改庭室情况
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:edit')")
    @Log(title = "庭室情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShiftScheduling shiftScheduling) {
        return toAjax(shiftSchedulingService.updateShiftScheduling(shiftScheduling));
    }

    /**
     * 删除庭室情况
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:remove')")
    @Log(title = "庭室情况", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shiftSchedulingService.deleteShiftSchedulingByIds(ids));
    }
}
